package com.story.web.controllers;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.story.domain.SessionEntity;
import com.story.web.shiro.dao.UserSessionDao;
@Controller
@RequestMapping("/manager")
public class OnlineController extends BaseController {
	@Autowired
	private UserSessionDao userSessionDao;
	
	public List<SessionEntity> getOnlineAll(){
		List<SessionEntity> sessions = userSessionDao.listActiveSessions();
		for(SessionEntity sessionEntity : sessions){
			System.out.println(sessionEntity.getJsessionId());
			System.out.println(sessionEntity.getLoginName());
			System.out.println(sessionEntity.getLoginIp());
			System.out.println(sessionEntity.getStartLoginTime());
			System.out.println(sessionEntity.getLastAccessTime());
		}		
		return sessions;
	}	
	@RequestMapping("/online/page/show")
	@ResponseBody
	public Map<String,Object> getOnlineWithLimit(Integer pageNum,Integer pageSize){
		List<SessionEntity> sessionEntitys = userSessionDao.listActiveSessionsWithLimit(pageNum, pageSize);
		Integer count = userSessionDao.getActiveSessionsCount();
		Map<String,Object> map = new LinkedHashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "查询成功！");
		map.put("count", count);
		map.put("data", sessionEntitys);
		return map;
	}
}
